<template>
  <div class="pzxq-page">
    <CommonHeader type="白" leftIcon title="信息详情" />
    <div class="pzxq-content">
      <div>
        <div class="item-title">品种名称：{{ dataValue.varietyName }}</div>
        <div class="item-content">
          审定编号：{{ dataValue.varietyApprovalNo }}
        </div>
        <div class="item-content">种子企业：{{ dataValue.companyName }}</div>
        <div class="item-content">许可证号：{{ dataValue.licenceNo }}</div>
        <div v-if="isGuoJia" class="item-content">
          制种面积：{{
            uiUtil.getNumberData2(dataValue.seedAreaTotal, "亩", true)
          }}
        </div>
        <div v-if="isGuoJia" class="item-content">
          制种产量：{{
            uiUtil.getNumberData2(dataValue.liJiShengChan, "公斤", true)
          }}
        </div>
        <div v-if="isGuoJia" class="item-content">
          收储数量：{{
            uiUtil.getNumberData2(dataValue.purchaseTotal, "公斤", true)
          }}
        </div>
        <div v-if="isGuoJia" class="item-content">
          加工数量：{{
            uiUtil.getNumberData2(dataValue.produceTotal, "公斤", true)
          }}
        </div>
        <div v-if="isGuoJia" class="item-content">
          包装数量：{{
            uiUtil.getNumberData2(dataValue.packageTotal, "公斤", true)
          }}
        </div>
      </div>
      <div v-if="locations">{{locations}}</div>
      <div>
        <div v-if="isGuoJia" class="item-content">
          调出省份：{{ dataValue.diaoYunShengShu }} (个)
        </div>
        <div v-if="isGuoJia" class="item-content">
          调出数量：{{
            uiUtil.getNumberData2(dataValue.transportOutTotal, "公斤", true)
          }}
        </div>
        <div v-if="isGuoJia" class="item-content">
          种植省份：{{ dataValue.daTianShengShu }} (个)
        </div>
        <div class="item-content">
          调入数量：{{
            uiUtil.getNumberData2(dataValue.transportTotal, "公斤", true)
          }}
        </div>
        <div class="item-content">
          销售数量：{{
            uiUtil.getNumberData2(dataValue.saleTotal, "公斤", true)
          }}
        </div>
        <div class="item-content">
          购种农户数：{{ dataValue.farmerTotal }} (户)
        </div>
        <div class="item-content">
          种植面积：{{
            uiUtil.getNumberData2(dataValue.plantAreaTotal, "亩", true)
          }}
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, defineProps, defineEmits, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import uiUtil from "@/util/UiUtil.js";
const router = useRouter();
const route = useRoute();
const pz = ref(route.query.name);
const dataValue = ref({});
const RegionID = ref(uiUtil.user.RegManageRegionID);
const isGuoJia = ref(uiUtil.user.UserRoleID == "1");
const locations = ref(null);
uiUtil.onMounted(async () => {
  getData();
  // initLocation();
  // getLocation();
});

function initLocation() {
  if (window.Android && window.Android.startLocation) {
    window.Android.startLocation();
    // 你可以在这里处理用户信息
    console.log("Android接口可用");
  } else {
    console.log("Android接口不可用");
  }
}

function getLocation() {
  if (window.Android && window.Android.getLocation) {
    let loca = JSON.parse(window.Android.getLocation());
    console.log("sssssssss", loca);
    if (loca && loca.v && loca.v.adcode) {
      locations.value = [];
      locations.value.push({
        code: "999999",
        name: "全国",
      });
      locations.value.push({
        code: loca.v.adcode.substring(0, 2) + "0000",
        name: loca.v.province,
      });
      locations.value.push({
        code: loca.v.adcode.substring(0, 4) + "00",
        name: loca.v.city,
      });
      locations.value.push({
        code: loca.v.adcode,
        name: loca.v.district,
      }); 
    }
    console.log("Android接口不可用", locations.value);
  } else {
    console.log("Android接口不可用");
  }
}

const getData = () => {
  const params = {
    searchVarietyName: pz.value,
    regionCode: RegionID.value,
    crop: "",
  };
  uiUtil.http().getObj({
    url: uiUtil.urlPath.searchVarietyByVarietyName,
    data: params,
    start: () => {
      uiUtil.toastLoading();
    },
    succeed: (res) => {
      // loading.value = false;
      // debugger
      // console.log('1ucceed=', res)
      if (!res || !res.code || 200 != res.code) {
        uiUtil.toastFail(res.msg);
        return;
      }
      if (!res.data || !res.data[0]) {
        // 如果返回数据为空，表示已加载完成
        uiUtil.toastClose();
        return;
      }

      dataValue.value = res.data[0];
      uiUtil.toastClose();
    },
    failed: (res) => {
      // debugger
      console.log("failed=", res);
      uiUtil.toastFail("失败");
    },
    finish: () => {
      uiUtil.toastClose();
    },
  });
};
</script>

<style scoped lang="less">
.pzxq-page {
  background: url("@/assets/img/main/all_bg.png") no-repeat;
  background-size: 100%;
  display: flex;
  flex-direction: column;
  height: 100vh;
  .pzxq-content {
    flex-grow: 1;
    overflow: auto;
    display: flex;
    flex-direction: column;
    justify-content: start;
    background-color: #fff;
    padding-bottom: 50px;
  }
  .item-title {
    min-height: 40px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding-left: 10px;
    padding-right: 10px;
    background-color: #f4fceb;
    border-radius: 4px 4px 0 0;
    box-sizing: border-box;
  }
  .item-content {
    min-height: 35px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding-left: 10px;
    padding-right: 10px;
    border-radius: 4px 4px 0 0;
    box-sizing: border-box;
  }
}
</style>
